<?php
/*
 * @Package Softpin Order Manager
 * @Subpackage : simorder Manager
 * Create by : thuc.lehuy@gmail.com
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php JHTML::_('behavior.tooltip'); ?>
<form action="index.php" method="post" name="adminForm">
    <table>
        <tr>
            <td align="left" width="100%">
                <?php echo 'Tìm theo Email'; ?>:
                <input type="text" name="search" id="search" value="<?php echo htmlspecialchars($this->lists['search']); ?>" class="text_area" onchange="document.adminForm.submit();" />
                <button onclick="this.form.submit();"><?php echo JText::_('Go'); ?></button>
                <button onclick="document.getElementById('search').value='';this.form.submit();"><?php echo JText::_('Reset'); ?></button>
            </td>
            <td nowrap="nowrap">
                <?php
//                echo $this->lists['type'];
                echo $this->lists['state'];
                ?>
            </td>
        </tr>
    </table>
    <table class="adminlist">
        <thead>
            <tr>
                <th width="20">
                    <?php echo "stt"; ?>
                </th>
                <th width="20">
                    <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Số sim', 'sim_numb_sim', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Giá', 'price', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Thuộc Kho', 'admin_name', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Thuộc mạng', 'provider_name', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Thuộc loại', 'categori_name', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Tên', 'p.name', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Điện thoại', 'p.tel', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Địa chỉ', 'p.address', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Nội dung', 'p.require', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Ngày đặt', 'p.datetime_created', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'Trạng thái', 'p.del_flag', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
                <th class="title">
                    <?php echo JHTML::_('grid.sort', 'ID', 'p.sim_order_id', @$this->lists['order_Dir'], @$this->lists['order']); ?>
                </th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td colspan="12">
                    <?php echo $this->pagination->getListFooter(); ?>
                </td>
            </tr>
        </tfoot>
        <tbody>
            <?php
            $k = 0;
            $db =& JFactory::getDBO();
            for ($i = 0, $n = count($this->items); $i < $n; $i++) {
                $row = & $this->items[$i];
                $checked = JHTML::_('grid.id', $i, $row->sim_order_id);

                // get sim info
                $query = 'SELECT p.*, pr.provider_name, c.categori_name, a.admin_name'
                . ' FROM #__sim AS p'
                . ' LEFT JOIN #__sim_provider AS pr ON pr.provider_id = p.provider_id and pr.del_flag = 0'
                . ' LEFT JOIN #__sim_categories AS c ON c.categori_id = p.categori_id and c.del_flag = 0'
                . ' LEFT JOIN #__sim_admin AS a ON a.admin_id = p.admin_id and a.del_flag = 0'
                . ' WHERE p.sim_id = '.$row->sim_id;
                $db->setQuery( $query );
                $sim = $db->loadResult();
                if ($db->getErrorNum()) {
                    echo $db->stderr();
                    return false;
                }

            ?>
                <tr class="<?php echo "row$k"; ?>">
                    <td>
                        <?php echo $i+ $this->pagination->limitstart; ?>
                    </td>
                    <td>
                    <?php echo $checked; ?>
                    </td>
                    <td>
                    <?php echo $row->sim_numb_sim; ?>
                    </td>
                    <td>
                    <?php echo JUtility::thousandseperate($row->price); ?>.000 <?php echo $row->curency; ?>
                    </td>
                    <td>
                    <?php echo $row->admin_name; ?>
                    </td>
                    <td>
                     <?php echo $row->provider_name; ?>
                    </td>
                    <td>
                     <?php echo $row->categori_name; ?>
                    </td>
                    <td>
                    <?php echo $row->name; ?>
                    </td>
                    <td>
                    <?php echo $row->tel; ?>
                    </td>
                    <td>
                    <?php echo $row->address; ?>
                    </td>
                    <td>
                    <?php echo $row->require; ?>
                    </td>
                    <td>
                    <?php echo $row->datetime_created; ?>
                    </td>
                    <td>
                    <?php
                        if ($row->del_flag) {
                            echo("Hoàn thành");
                        } else {
                            echo("Đang chờ");
                        }
                    ?>
                    </td>
                    <td>
                    <?php echo $row->sim_order_id; ?>
                    </td>
                </tr>
            <?php
                        $k = 1 - $k;
                    }
            ?>
                </tbody>
    </table>
    <input type="hidden" name="option" value="com_simorder" />
    <input type="hidden" name="task" value="" />
    <input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="controller" value="simorder" />

    <input type="hidden" name="filter_client" value="<?php echo $this->client; ?>" />
    <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
    <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
    <?php echo JHTML::_('form.token'); ?>
</form>
